<!-- 待审核 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10">防伪码列表</p>
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :qx="qx"
      ref="databale"
      :headBtn="headBtnw"
    ></dxtable>

    <n-modal v-model:show="xczerteterty" preset="card" class="sdfdsfrttt">
      <template #header>
        <div>批量新增</div>
      </template>
      <div class="cvsdrty">
        <n-input-group>
          <n-input-number
            placeholder="请输入数量"
            min="1"
            v-model:value="jnzdfsdf"
            :allow-input="noSideSpace"
          />
          <n-button type="primary" :loading="sdfsdrfrt" @click="pidfdsftrt">
            确定
          </n-button>
        </n-input-group>
      </div>
    </n-modal>
  </div>
</template>
<script lang="ts" setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost } from "../../util/index";
import { NButton, NImage, NTag } from "naive-ui";
import { h, ref, reactive } from "vue";
const databale = ref();
const xczerteterty = ref();
const showModal = ref(false);
const rowData = ref({});
const shhehsdrt = ref();
const hjshsd = ref();
const sdfsdrfrt = ref(false);
const kjdsfsd = ref();
const initeer = () => {
  databale.value.initDataExpose();
};
const jnzdfsdf = ref(1);
const noSideSpace = (value) => {
  return !value.startsWith(" ") && !value.endsWith(" ");
};
const headBtnw = ref([
  {
    name: "批量添加",
    jy: true,
    clickFun: () => {
      xczerteterty.value = true;
    },
  },
  {
    name: "批量普通二维码",
    loading:false,
    clickFun: async (row, obj) => {
      const jdfsdfs = [];
      obj.map((a) => {
        jdfsdfs.push(a.qcurl);
      });
      headBtnw.value[1].loading = true
      const { data } = await dxpost("fwm/kouzi/index", {
        urls: jdfsdfs,
      });
      headBtnw.value[1].loading = false
      window.location.href = data.result;
    },
  },
  {
    name: "批量下载需要验证4位数二维码",
    loading:false,
    clickFun: async (row, obj) => {
      const jdfsdfs = [];
      obj.map((a) => {
        jdfsdfs.push(a.siqcurl);
      });
      headBtnw.value[2].loading = true
      const { data } = await dxpost("fwm/kouzi/index", {
        urls: jdfsdfs,
      });
      headBtnw.value[2].loading = false
      window.location.href = data.result;
    },
  },
]);

let dataJson = [
  {
    title: "防伪码id",
    key: "id",
    width: 200,
    search: true,
  },
  {
    title: "普通二维码",
    key: "qcurl",
    type: "img",
  },
  {
    title: "输入后4位二维码",
    key: "siqcurl",
    type: "img",
  },
  {
    title: "查询次数",
    key: "cxcs",
  },
  {
    title: "首次查询时间",
    key: "sccx",
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "fwmindexdel", //删除
  EditPermissionIdentifier: "fwmindexadd", // 编辑
  NewPermissionIdentifier: "fwmindexxj", // 新建
  ViewPermissionID: "fwmindexck", // 查看
};
const portUrl = "fwm/fwlist/fwlist";

let formJson = reactive([]);
const pidfdsftrt = async () => {
  sdfsdrfrt.value = true;
  for (let i = 0; i < jnzdfsdf.value; i++) {
    const { data }: any = await dxget("fwm/api/piliangchus");
    let urlsder = encodeURIComponent(
      `https://www.duxinggj.com/fwm?id=${data}&lxsdr=2`
    );
    const qzx: any = await dxget("fwm/exportjpg", {
      url: "https://duxinggj.com/fwm/qccode?text=" + urlsder + "&fwid=" + data,
      wyid:data+'m'
    });
    await dxpost("fwm/fwlist/fwlist", { id: data, siqcurl: qzx.data }, "put");
  }
  sdfsdrfrt.value = false;
  xczerteterty.value = false;
  initeer();
};
// 获取字典内容
// const xtgxxmfl = async () => {
//   const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'xtgxxmfl' })
//   dataJson[2].options = [
//     {
//       label: "全部",
//       value: ""
//     },
//     ...data
//   ]
//   formJson[2].options = data
//   xmlxSelect.value = data
//   console.log(data);
// }
// xtgxxmfl()
</script>
<style scoped></style>
<style>
.sdfdsfrttt {
  width: 300px;
}
</style>
